package dt.inlee.system.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import dt.inlee.common.exception.FrameworkException;
import dt.inlee.common.util.SystemResourceUtil;
import dt.inlee.domain.SysDictionary;
import dt.inlee.system.service.SysDictionaryService;
import dt.inlee.system.vo.DictionaryBean;
import dt.inlee.system.vo.SysDictionaryBean;

/**
 * 功能说明：
 * 
 * @作者： 雷运梅 、谢朝胜 创建日期： 2010-5-6
 */

@SuppressWarnings("serial")
@Scope("prototype")
@Controller("PeelingAction")
public class PeelingAction extends ActionSupport {
	@Autowired
	private SysDictionaryService sysDictionaryService;
	private SysDictionaryBean sysDictionaryBean;
	private SysDictionary sysDictionary;
	private List<DictionaryBean> list = new ArrayList<DictionaryBean>();
	private boolean result = false;

	public boolean isResult() {
		return result;
	}

	public void setResult(boolean result) {
		this.result = result;
	}

	public List<DictionaryBean> getList() {
		return list;
	}

	public void setList(List<DictionaryBean> list) {
		this.list = list;
	}

	public SysDictionaryBean getSysDictionaryBean() {
		return sysDictionaryBean;
	}

	public void setSysDictionaryBean(SysDictionaryBean sysDictionaryBean) {
		this.sysDictionaryBean = sysDictionaryBean;
	}

	public SysDictionary getSysDictionary() {
		return sysDictionary;
	}

	public void setSysDictionary(SysDictionary sysDictionary) {
		this.sysDictionary = sysDictionary;
	}

	/**
	 * 通过CSS样式的ID获取样式颜色信息接口
	 * 
	 * @return
	 * @throws Exception
	 */
	@SkipValidation()
	@Action(value = "findSysPeelings", results = { @Result(type = "json", params = { "excludeNullProperties", "true",
			"excludeProperties", "sysDictionaryBean,sysDictionaryService,sysDictionary" }) })
	public String findSysPeelings() throws Exception {
		list = SystemResourceUtil.getInstance().getResourceAsList("peeling");
		return SUCCESS;
	}

	/**
	 * 修改CSS皮肤样式
	 * 
	 * @return
	 * @throws FrameworkException 
	 * @throws Exception
	 */
	@Action(value = "peelingChange", results = { @Result(type = "json", params = { "excludeNullProperties", "true",
			"includeProperties", "result" }) })
	public String peelingChange() throws FrameworkException {
		SysDictionary sysDictionary = sysDictionaryService.findSysDictionaryByName("PEELING_CHANGE", null);
		sysDictionary.setValue(sysDictionaryBean.getValue());
		sysDictionaryService.updateSysDictionary(sysDictionary);
		this.result = true;
		return SUCCESS;
	}
}